import requests
import re


def parse_page(url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
    }
    response = requests.get(url, headers=headers)
    text = response.text

    titles = re.findall(r'<div\sclass="cont">.*?<b>(.*?)</b>', text, re.DOTALL)
    dynasties = re.findall(r'<p\sclass="source">.*?<a.*?>(.*?)</a>', text, re.DOTALL)
    authors = re.findall(r'<p\sclass="source">.*?<a.*?>.*?<a.*?>(.*?)</a>', text, re.DOTALL)
    contents_tags=re.findall(r'<div\sclass="contson" .*?>(.*?)</div>', text, re.DOTALL)
    contents=[]
    for content in contents_tags:
        x=re.sub(r"<.*?>","",content)
        contents.append(x.strip())
    pemos=zip(titles,dynasties,authors,contents)
    for p in pemos:
        print(p)


def main():
    url = "https://www.gushiwen.org/default_1.aspx"
    parse_page(url)


if __name__ == '__main__':
    main()
